import axios from 'axios';
import type { CommonRes } from './commonType'
export interface PersonelItem  {
  id: number,
  nickname: string,
  username: string,
  mobile: number,
  uid: number,
  entry_status: string,
  status: string,
  updatetime: string,
}

export interface createPersonel {
  id: string,
  account: string,
  password: string,
  nickname: string,
  mobile: string,
  status: string,
  entry_status: number
}

export interface createPersonelRes {
  code: number,
  msg: string,
  time: string,
  data: any
}

export interface Res {
  code: number,
  msg: string,
  time: string,
  data: any
}


export interface UpdatePersonStatusEntity {
  id?: number,
  status?: string,
  entry_status?: string
}

export interface UpdatePersonRes {
  id: string,
  status: string,
  entry_status: string
}

export interface Datalist {
  total: number,
  per_page: string,
  current_page: number,
  last_page: number,
  data: any
}
export interface PersonnelListRes {
  datalist: any;
  code: number,
  msg: string,
  time: number,
  data: any
}

export interface SelectItem {
  id: number,
  nickname: string,
  op_uid: number,
}

export interface PersonnelSelectRes {
  code: number,
  msg: string,
  time: number,
  data: {
    datalist: SelectItem
  }
}

export interface PersonnelListQuery {
    page?: number,
    size?: number,
    status?: string,
}

export interface PersonelQueryOne {
    id: number | string
}

export interface UpdatePersonnelInfo {

}

export interface PersonnelDetail {
  details?: any;
  id: number,
  nickname: string,
  username: string,
  mobile: string,
  uid?: number,
  password?: string,
  entry_status?: number,
  status?: string,
  updatetime?: number,
  o_id?: number,
  pc_count?: number,
  pc_cooperative_price?: any
}

/**
 * 更新员工状态
 * @param data 
 * @returns 
 */
export function updatePersonStatus(data: UpdatePersonStatusEntity) {
  return axios.post<CommonRes>('/organization/Personnel/updatepart', data);
}

/**
 * 添加员工
 * @param data 
 * @returns 
 */
export function createPerson(data: createPersonel) {
  return axios.post<createPersonelRes>('/organization/Personnel/create', data);
}

/**
 * 获取员工下拉列表
 * @param data 
 * @returns 
 */
export function getPersonnelSelect() {
  return axios.post<PersonnelSelectRes>('/organization/Personnel/select');
}

/**
 * 获取员工列表
 * @param data 
 * @returns 
 */
export function getPersonnelList(data: PersonnelListQuery) {
  return axios.post<PersonnelListRes>('/organization/Personnel/listpage', data);
}


/**
 * 获取单个用户信息
 * @param data 
 * @returns 
 */
export function getPersonnelById(data: PersonelQueryOne) {
  return axios.post<PersonnelDetail>('/organization/Personnel/details', data);
}

/**
 * 更新用户信息
 * @param data 
 * @returns 
 */
export function updatePersonnel(data: PersonnelDetail) {
  return axios.post<PersonnelListRes>('/organization/Personnel/create', data);
}


export function deletePersonnel(data: { id: number, status: string, entry_status?:string }) {
  return axios.post<PersonnelListRes>('/organization/Personnel/updatepart', data);
}